package seqlist.oj;

/**
 * @Author: yuisama
 * @Date: 2019/12/11 11:21
 * @Description:相交链表解法2-双指针
 */
public class Solution160_1 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) {
            return null;
        }
        ListNode pA = headA;
        ListNode pB = headB;
        while (pA != pB) {
            pA = (pA == null)?headB:pA.next;
            pB = (pB == null)?headA:pB.next;
        }
        return pA;
    }
}
